package controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 高杰  gao4433@qq.com
 * @Description 登陆界面验证码
 * @date 2021/12/12 10:25
 * @since 1.8
 */

public class CodeServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();

        //验证码信息干扰的验证码
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,15);
        //将验证码图片响应输出流给客户端
        lineCaptcha.write(response.getOutputStream());

        String code = lineCaptcha.getCode();
        session.setAttribute("ccc",code);
        lineCaptcha.write(response.getOutputStream());

    }
}
